package com.then.recruitment.utils;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;

import java.util.UUID;

/**
 * Created by wk on 15/3/10.
 */
public class NetWorkUtils {
    public static String getWLANMACAddress(Context context) {
        String macAddress = "";
        WifiManager wm = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wm.getConnectionInfo();
        if (info != null) {
            macAddress = info.getMacAddress();
        } else {
            macAddress = "No Wifi Device";
        }
        return macAddress;
    }

    /**
     * 得到设备序列号
     *
     * @param context
     * @return
     */

    public static String getSimSerialNumber(Context context) {
        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getSimSerialNumber();
    }

    public static String getUniqueNumber(Context context) {
        String androidID = getAndroidID(context);
        String imei = getIMEI(context);
        String simSerialNumber = getSimSerialNumber(context);
        UUID uuid = new UUID(androidID.hashCode(),
                ((long) imei.hashCode() << 32) | simSerialNumber.hashCode());
        return uuid.toString();
    }

    public static String getAndroidID(Context context) {
        String androidID = Settings.Secure.getString(context.getContentResolver(),
                Settings.Secure.ANDROID_ID);
        return androidID;
    }

    /**
     * 得到设备IMEI值
     *
     * @param context
     * @return
     */
    public static String getIMEI(Context context) {
        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getDeviceId();
    }
    public static String getToken(Context context)
    {
        String token = getUniqueNumber(context)+getWLANMACAddress(context);
        return MD5Tools.getMD5_Str(token);
    }
}
